package com.cn.clp.controller;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.cn.clp.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cn.clp.service.UserService;

@Controller
//@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/login")
	public String login(HttpServletRequest request, Model model) {
		String code = request.getParameter("usercode");
		String pwd = request.getParameter("password");
		User user_login = userService.findById(code,pwd);
		System.out.println("--->"+user_login);
		
		if (null == user_login) {
			System.out.println("Error login!");
			return "redirect:index.jsp?oper=error";
		} else {
			model.addAttribute("user", user_login);
			return "pages/success";
		}
	}
	
	
}

